package com.lyf.shop.web.controller.admin;

import com.lyf.shop.common.Const;
import com.lyf.shop.entity.Orders;
import com.lyf.shop.services.Impl.OrderServiceImpl;
import com.lyf.shop.services.OrderService;
import com.lyf.shop.web.controller.BaseController;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/admin_order")
public class AdminOrderController extends BaseController {
    private OrderService orderService = new OrderServiceImpl();

    /**
     * 发货
     *
     * @param request
     * @param response
     * @return
     */
    public String sendOrder(HttpServletRequest request, HttpServletResponse response) {
        String oid = request.getParameter("oid");
        //访问业务层进行数据的修改
        orderService.updateOrderStateToSend(oid, Const.OrderConst.ORDER_SEND);
        return Const.REDIRECT + "/admin_order?method=getAllOrder";
    }

    /**
     * 查询所有订单  动态查询
     *
     * @param request
     * @param response
     * @return
     */
    public String getAllOrder(HttpServletRequest request, HttpServletResponse response) {
        //获取的参数
        String uname = request.getParameter("uname");
        String ostate = request.getParameter("ostate");

        //访问业务层 获取数据
        List<Orders> allOrders = orderService.getAllOrders(uname, ostate);
        request.setAttribute("orderList", allOrders);
        return Const.FORWARD + "/admin/showAllOrder.jsp";
    }
}
